package com.example.demo;

import org.apache.commons.lang3.StringUtils;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2016</p>
 * <p>Company: Sunshine Insurance Group Co., Ltd.</p>
 *
 * @author lbb
 * @version 1.0
 * 修改记录：
 * 修改序号，修改日期，修改人，修改内容
 */
public class ProxyInterceptor implements MethodInterceptor {

    private Object target;

    public ProxyInterceptor(Object object) {
        super();
        this.target = object;
    }

    @Override
    public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
        Object result = null;
        if(target != null){
            result = method.invoke(target, args);
        }else {
            result = proxy.invokeSuper(obj, args);
        }
        if(result != null && result instanceof String) {
            result = StringUtils.isBlank((String) result) ? null : result;
        }
        return result;
    }
}
